package com.backend.securitiessystem.service.impl;

import com.backend.securitiessystem.dao.IFlashDao;
import com.backend.securitiessystem.dto.FlashDto;
import com.backend.securitiessystem.pojo.Flash;
import com.backend.securitiessystem.service.FlashService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;

/**
 * Flash服务impl
 *
 * @author LWY
 * @date 2024-05-23 03:38:14
 */
@Service
public class FlashServiceImpl extends ServiceImpl<IFlashDao, Flash> implements FlashService {


    @Override
    public IPage<FlashDto> selectPageWithCondition(int current, int size, QueryWrapper<Flash> queryWrapper) {
        queryWrapper.orderByDesc("time");
        Page<Flash> page1 = new Page<>(current, size);
        IPage<Flash> newShareIPage = this.page(page1, queryWrapper);

        List<FlashDto> flashDtos = new ArrayList<>();
        for (Flash flash : newShareIPage.getRecords()) {
            FlashDto flashDto = new FlashDto();
            flashDto.setTitle(flash.getTitle());
            flashDto.setTime(flash.getTime());
            flashDto.setType(flash.getType());
            flashDtos.add(flashDto);
        }
        IPage<FlashDto> flashDtoIPage = new Page<>();
        flashDtoIPage.setRecords(flashDtos);
        flashDtoIPage.setCurrent(current);
        flashDtoIPage.setSize(size);
        flashDtoIPage.setTotal(newShareIPage.getTotal());
        return flashDtoIPage;
    }
}
